
from django.db import models
# 权限子表
from django.utils.timezone import now

class Metalist(models.Model):
    id = models.IntegerField(primary_key=True)
    icon = models.CharField(max_length=32, verbose_name='图标')
    title = models.CharField(verbose_name='权限名称', max_length=32)
    type = models.CharField(default='menu', max_length=32)
    affix=models.BooleanField(default=False)

# 菜单表
class Menu(models.Model):
    name = models.CharField(verbose_name='路径名称', max_length=32, default='')
    path = models.CharField(verbose_name='权限路径', max_length=32)
    component = models.CharField(verbose_name='组件名称', max_length=32, null=True)
    mid = models.ForeignKey(to='self', on_delete=models.CASCADE, default=None,blank=True, null=True, related_name='children')
    metalist = models.ForeignKey(Metalist, on_delete=models.CASCADE, default=None,related_name='meta')
    status=models.BooleanField(default=True,verbose_name='状态')
    menuTime=models.DateField(verbose_name='创建菜单时间',default=now)
    identify=models.CharField(verbose_name='权限标识',max_length=32,null=True)
    #排序，菜单图标，菜单类目，商机类目，是否外链，显示状态
# 角色表
class Role(models.Model):
    Gender_choices = (
        (0, '正常'),
        (1, '锁定')
    )
    role = models.CharField(verbose_name='角色名称', max_length=32)
    status = models.IntegerField(choices=Gender_choices, default=0, verbose_name='角色状态')
    menus = models.ManyToManyField(to=Menu)
    identify=models.CharField(verbose_name='权限标识',max_length=32,null=True)
    roleTime=models.DateField(verbose_name='创建角色时间',default=now)
    # 角色顺序，备注

#部门表
class Depart(models.Model):
    depName=models.CharField(verbose_name='部门名称',max_length=32)
    statu=models.BooleanField(default=True,verbose_name='状态')
    depTime=models.DateField(auto_now_add=True,verbose_name='创建时间')
    did=models.ForeignKey(to='self',default=None,null=True,related_name='children',on_delete=models.CASCADE)

# 用户表
class User(models.Model):
    user = models.CharField(verbose_name='用户名', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=32)
    phone = models.CharField(verbose_name='手机号', max_length=11)
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    role = models.ManyToManyField(Role)
    headPicture = models.URLField(verbose_name='头像', blank=True)
    nickName=models.CharField(max_length=32,verbose_name='用户昵称',default='')
    depart=models.ForeignKey(to=Depart,on_delete=models.DO_NOTHING,default=1)
    #性别，岗位，邮箱

#岗位表
class Post(models.Model):
    postName=models.CharField(max_length=32,verbose_name='岗位名称')
    postCode=models.CharField(max_length=32,verbose_name='岗位编码')
    postStatus=models.BooleanField(default=True,verbose_name='岗位状态')
    postTime=models.DateField(auto_now_add=True,verbose_name='创建时间')